package spring.cloud.eurekaclientproduct.filter;

import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

//可以使用filter过滤器 先初始化HystrixRequestContext 对象
//@WebFilter(filterName = "HystrixRequestContextFilter",urlPatterns = "/user/info/cache")
//@Component
public class HystrixRequestContextFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HystrixRequestContext context = HystrixRequestContext.initializeContext();
        try{
            chain.doFilter(request, response);
        }finally {
            context.shutdown();
        }
    }
}
